/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package beans;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author machine
 */
@Stateless
public class PersonasFacade extends AbstractFacade<Personas> implements PersonasFacadeLocal {
    @PersistenceContext(unitName = "videosJEE-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public PersonasFacade() {
        super(Personas.class);
    }

    @Override
    public Integer contarPersonasVideo(Integer idpeliculas) {
        Long rowCnt = (Long) em.createNativeQuery("SELECT count(1) FROM personapeliculas ip where ip.idpeliculas = "+idpeliculas+"  ").getSingleResult(); 
        return rowCnt.intValue();
    }

    @Override
    public Personas consultarPersona(String persona) {
        Query q = em.createQuery( "SELECT p FROM Personas p WHERE p.idpersonas = " + persona + " " );
        return (Personas) q.getSingleResult();
    }
    
}
